<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>异步加载地图</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>    
</head>
<body>
<div id="container"></div>
<script src="http://webapi.amap.com/maps?v=1.4.3&key=378db6b095a21931cb88ef1d3ff535c0&callback=init"></script>
<script>
 if (navigator && navigator.geolocation && navigator.geolocation.getCurrentPosition) {
        navigator.geolocation.getCurrentPosition(function(ret) {
                window.longitude = ret.coords.longitude;
                window.latitude = ret.coords.latitude;

                console.log(longitude);
                console.log(latitude);

                  var map = new AMap.Map('container', {
                      resizeEnable: true,
                      zoom:11,
                      center: [longitude, latitude]
                  });
                  }, function(ret) {},
            {
                //开启高精度定位
                enableHighAccuracy : true,
                timeout : 2000,
                maximumAge : 300000
            });
    }
    function init(){
        var map = new AMap.Map('container', {
            center: [longitude, latitude],
            zoom: 11
        });
        map.plugin(["AMap.ToolBar"], function() {
            map.addControl(new AMap.ToolBar());
        });
    }
</script>
</body>
</html>
